﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MbUnit.Framework;
using System.IO;

namespace Frost.Tests.FitTestSpecs  {
    
    [TestFixture]
    public class when_reading_valid_fit_test {
        private FitTest _FitTest;
        private TextReader _textStream;

        [SetUp]
        public void Setup() {
            _FitTest = new FitTest();
            _textStream = new StringReader(@" 
            <html>
            <body>
                <table>
                <tr><td>SomeFixture.blah blah</td></tr>
                </table>
            </body>
            </html>
            ");
            _FitTest.LoadTest(_textStream);
        }

        [Test]
        public void should_load_all_text() {
            _FitTest.InputText.ShouldNotBeEmpty();
        }

        [Test]
        public void should_parse_tables() {
            _FitTest.ParsedFit.ShouldNotBeNull();
        }

        [Test]
        public void should_have_no_exceptions() {
            _FitTest.Exceptions.ShouldBeEmpty();
        }
    }

    [TestFixture]
    public class when_fit_test_is_empty {
        protected FitTest _FitTest;
        protected TextReader _textStream;

        [SetUp]
        public void Setup() {
            _FitTest = new FitTest();
            _textStream = new StringReader(string.Empty);

            _FitTest.LoadTest(_textStream);
        }

        [Test]
        public void should_set_is_failure() {
            _FitTest.IsFailure.ShouldbeTrue();
        }
        
        [Test]
        public void should_have_empty_text() {
            _FitTest.InputText.ShouldBeEmpty();
        }

        [Test]
        public void should_set_valid_to_false() {
            _FitTest.IsValid.ShouldBeFalse();
        }

        [Test]
        public void should_append_exception_to_exceptions() {
            _FitTest.Exceptions.Count.ShouldBeGreaterThan(0);
        }
    }

    [TestFixture]
    public class when_fit_test_contains_no_tables {
        protected FitTest _FitTest;
        protected TextReader _textStream;

        [SetUp]
        public void Setup() {
            _FitTest = new FitTest();
            _textStream = new StringReader("<html><body><div>No tables</div></body></html>");

            _FitTest.LoadTest(_textStream);
        }

        [Test]
        public void should_have_input_text() {
            _FitTest.InputText.ShouldNotBeEmpty();
        }

        [Test]
        public void should_set_valid_to_false() {
            _FitTest.IsValid.ShouldBeFalse();
        }

        [Test]
        public void should_set_failure_to_true() {
            _FitTest.IsFailure.ShouldbeTrue();                                    	
        }

        [Test]
        public void should_have_exceptions() {
            _FitTest.Exceptions.ShouldNotBeEmpty();            
        }
    }
}
